﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Warensoft.Unity.Communication.Client.Contracts;

namespace Warensoft.Unity.Communication.Client
{
    public abstract class PackageManagerBase:IDisposable
    {
        protected Queue<byte> messageQueue =new Queue<byte>();
        public object[] AddToQueue(byte[] buffer)
        {
            for (int i = 0; i < buffer .Length; i++)
            {
                this.messageQueue.Enqueue(buffer [i]);
            }
           
            return this.ProcessQueueToPackage();
        }
        public object[] AddToQueue(byte[] buffer, int offset, int count)
        {
            for (int i = offset; i < offset+count; i++)
            {
                this.messageQueue.Enqueue(buffer [i]);
            }

            return this.ProcessQueueToPackage();
        }
        public void RemoveFromQueue(int count)
        {
            for (int i = 0; i < count ; i++)
            {
                this.messageQueue.Dequeue();
            }
        }
        protected abstract object[] ProcessQueueToPackage();

        public void Dispose()
        {
            this.messageQueue.Clear();

        }
    }
}
